package monitoring;


public class UssProjectUpdateChecker extends Thread {
	private UssProjectView project;

	public UssProjectUpdateChecker(UssProjectView project) {
		this.project = project;
	}

	public void run() {

		String s = new String();
		int i = 0;
		while (true) {

			// #######################################################
			// Checking the handshaking entry -- DIFFICULT TO DO
			// #######################################################

			// String str = client.remote.handShake();
			// client.dialogue.append(str);

			// #######################################################
			// Buffer Server
			// #######################################################

			project.server.buff.flip();
			
			// reading from the buffer
			char[] str1 = new char[2048];
			
			i = 0;
			while (project.server.buff.hasRemaining()) {
				str1[i++] = project.server.buff.get();
			}
			
			s = new String(str1).substring(0, i);
			project.textServer.append(s);

			// #######################################################
			// Buffer Storage
			// #######################################################

			project.storage.buff.flip();
			
			// reading from the buffer
			char[] str2 = new char[2048];
			
			i = 0;
			while (project.storage.buff.hasRemaining()) {
				str2[i++] = project.storage.buff.get();
			}
			
			s = new String(str2).substring(0, i);
			project.textStorage.append(s);
			
			// #######################################################
			// Buffer Hi-fi
			// #######################################################
			
			// reading from the buffer
			char[] str3 = new char[2048];
			i = 0;
			
			if ("LOUD" == project.hifiType) {
				project.hifiLoud.buff.flip();
				
				while (project.hifiLoud.buff.hasRemaining()) {
					str3[i++] = project.hifiLoud.buff.get();
				}
			}
			else if ("MEDIUM" == project.hifiType) {
                project.hifiMedium.buff.flip();
				
				while (project.hifiMedium.buff.hasRemaining()) {
					str3[i++] = project.hifiMedium.buff.get();
				}
			}
            else if ("QUIET" == project.hifiType) {
                project.hifiQuiet.buff.flip();
				
				while (project.hifiQuiet.buff.hasRemaining()) {
					str3[i++] = project.hifiQuiet.buff.get();
				}
			}
			
			s = new String(str3).substring(0, i);
			project.textServer.append(s);

			try {
				sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		} // end of while

	}

}
